class EffectNum {
	obj: egret.DisplayObject;

	ox: number;

	oy: number;

	constructor(obj: egret.DisplayObject) {
		this.obj = obj;
		this.ox = obj.x;
		this.oy = obj.y;
	}

	setEffect(effect: string): egret.Tween {
		// console.log('setEffectNum', effect, this.obj.x, this.obj.y, this.obj.width, this.obj.height);
		if (effect === 'parabola') {
			const tw = egret.Tween.get(this)
				.to({ scaleX: 2.2, scaleY: 2.2, alpha: 1 }, 180)
				.to(
					{
						scaleX: 0.9,
						scaleY: 0.9,
						parabola: 1,
						alpha: 0.7,
					},
					650,
				)
				.call(this.tweenComplete, this, []);
			return tw;
		}
		if (effect === 'normal') {
			const { y } = this.obj;
			const tw = egret.Tween.get(this.obj)
				.to({ alpha: 1 }, 1)
				.to({ scaleX: 1.35, scaleY: 1.35 }, 70)
				.to({ scaleX: 1.05, scaleY: 1.05 }, 70)
				.wait(200)
				.to({ y: y - 40, alpha: 0 }, 500);
			return tw;
		}
		if (effect === 'sp') {
			const { x } = this.obj;
			this.obj.x = x + 40;
			const tw = egret.Tween.get(this.obj)
				.to({ alpha: 1 }, 1)
				.to({ scaleX: 1.35, scaleY: 1.35 }, 70)
				.to({ scaleX: 1.05, scaleY: 1.05 }, 70)
				.wait(200)
				.to({ x: x + 140, alpha: 0 }, 500);
			return tw;
		}
		return null;
	}

	tweenComplete(): void {
		// ui.msglog('tweenComplete');
	}

	public get alpha(): number {
		return this.obj.alpha;
	}

	public set alpha(v: number) {
		this.obj.alpha = v;
	}

	public get scaleX(): number {
		return this.obj.scaleX;
	}

	public set scaleX(v: number) {
		this.obj.scaleX = v;
	}

	public get scaleY(): number {
		return this.obj.scaleY;
	}

	public set scaleY(v: number) {
		this.obj.scaleY = v;
	}

	public get parabola(): number {
		return 0;
	}

	public set parabola(num: number) {
		const value = 1;
		this.obj.x =
			this.ox + (1 - num) * (1 - num) * 3 + 2 * value * (1 - num) * 26 + num * num * 43;
		this.obj.y =
			this.oy + (1 - num) * (1 - num) * -7 + 2 * value * (1 - num) * -100 + num * num * 17;
		// console.log('parabola', num, this.obj.x, this.obj.y);
	}
}

// autoremove = 2 push to Pool!
function setEffectNum(obj: egret.DisplayObject, effect: string, autoremove = 0): egret.Tween {
	const num = new EffectNum(obj);
	const tw = num.setEffect(effect);
	if (tw && autoremove) {
		tw.call(() => {
			if (autoremove > 0) safeRemoveFromFather(obj);
			if (autoremove > 1) Pool.ins().pushSys(obj);
		});
	}
	return tw;
}
